<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('orders', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('order_number')->default('')->comment('订单号');
            $table->unsignedBigInteger('user_id')->comment('用户');
            $table->unsignedInteger('school_id')->comment('学校');
            $table->unsignedTinyInteger('type')->comment('类型 1跑腿 2其他任务');
            $table->unsignedInteger('unit_block_id')->nullable()->comment('单元楼');
            $table->string('room_number')->nullable()->comment('房间号');
            $table->decimal('amount')->comment('金额');
            $table->decimal('handling_fee')->default('0')->comment('手续费（发布者承担）');
            $table->decimal('order_taking_fee')->default('0')->comment('接单费用（跑男承担）');
            $table->timestamp('cut_off_at')->comment('截止时间');
            $table->string('pickup_code')->nullable()->comment('取件码');
            $table->string('write_off_code')->comment('核销码');
            $table->string('write_off_code_url')->comment('核销二维码');
            $table->string('description')->default('')->comment('描述');
            $table->json('images')->nullable()->comment('图片');
            $table->unsignedTinyInteger('status')->default(1)->comment('状态 1待生效 2待审核 3待接单 4审核失败 5已接单 6已完成 7已取消');
            $table->string('fail_reason')->nullable()->comment('驳回原因');
            $table->unsignedBigInteger('run_errand_id')->nullable()->comment('跑男');
            $table->timestamp('paid_at')->nullable()->comment('支付时间');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('orders');
    }
}
